﻿using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ComponentModel;

namespace LLServer.Chat
{
    [DataContract]
    public class Message : INotifyPropertyChanged, IComparer<Message>
    {
        Client _sender;
        string _content;
        DateTime _time;
        bool _respond;
        
        [DataMember(IsRequired = true)]
        public bool Respond
        {
            get { return _respond; }
            set { _respond = value;
                this.OnPropertyChanged("Respond");
            }
        }

        [DataMember(IsRequired = true)]
        public Client Sender
        {
            get { return _sender; }
            set
            {
                _sender = value;

                this.OnPropertyChanged("Sender");
            }
        }

        [DataMember(IsRequired = true)]
        public string Content
        {
            get { return _content; }
            set
            {
                _content = value;

                this.OnPropertyChanged("Content");
            }
        }

        [DataMember(IsRequired = true)]
        public DateTime Time
        {
            get { return _time; }
            set
            {
                _time = value;

                this.OnPropertyChanged("Time");
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string propName)
        {
            if (PropertyChanged != null)
            {
                PropertyChangedEventArgs e = new PropertyChangedEventArgs(propName);

                PropertyChanged(this, e);
            }
        }

        public int Compare(Message x, Message y)
        {
            if (x.Sender == y.Sender && string.Compare(x.Content, y.Content) == 1)
            {
                return 1;
            }

            return 0;
        }
    }
}